<template>
	<div>
		<Header class="header">
			<span class="title">更新 </span>
			<div class="close" @click="closeHandle">
				<span>X</span>
			</div>
		</Header>

		<div class="update-box">
			<Logo width="5.25rem" height="4.38rem"></Logo>

			<div class="content">
				<p class="title">发现新版本：{{ data.version }}</p>
				<div class="desc">
					<p class="desc-title">更新详情：</p>
					<div v-html="list"></div>
				</div>
				<div class="action">
					<Button type="primary" @click="clickUpdate">立即升级</Button>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
import Logo from '@/components/svg/logo.vue'
export default {
	components: {
		Logo
	},
	data() {
		return {
			data: {
				version: '',
				remark: ''
			}
		}
	},
	methods: {
		clickUpdate() {
			// 立即更新
			chrome.webview.hostObjects.form.OnPageEvent('updatenow')
		},
		closeHandle() {
			chrome.webview.hostObjects.form.OnPageEvent('close')
		}
	},
	computed: {
		list() {
			let strs = []
			if (this.data.remark && this.data.remark !== '') {
				this.data.remark
					.replace(/<br\/>/g, '#')
					.split('#')
					.forEach((item) => {
						strs.push(`<p class='desc-content' style='margin-bottom: 0.5rem;'>${item}</p>`)
					})
			}

			return strs.join('')
		}
	},
	mounted() {
		// 获取更新信息
		chrome.webview.hostObjects.form.GetVersionAsync().then((res) => {
			console.log(res)
			const { version, remark, url } = JSON.parse(res)
			this.data = { version, remark, url }
		})
	}
}
</script>
<style lang="less" scoped>
.header {
	background: var(--setting-header-bg-color);
	display: flex;
	justify-content: space-between;
	padding: 0 1.87rem;
	// border-bottom: 1px solid #ddd;
	app-region: drag;
	height: 3.5rem;
	line-height: 3.5rem;
	.title {
		font-family: PingFangSC-Medium;
		letter-spacing: 0;
		font-size: 1.13rem;
		color: var(--text-color);
		font-weight: 600;
	}
	.close {
		cursor: pointer;
		font-size: 1.13rem;
		app-region: no-drag;
		color: var(--header-close-color);
	}
}
.update-box {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	/deep/.fill-color {
		fill: var(--bg-color);
	}
	/deep/.fill-color2 {
		fill: var(--svg-logo-color);
	}
	.content {
		display: flex;
		flex-direction: column;
		// margin-left: 32px;
		.title {
			font-family: PingFangSC-Semibold;
			font-size: 1.25rem;
			color: var(--setting-text-title-color);
			letter-spacing: 0;
			font-weight: 600;
			margin-top: 0.99rem;
			margin-bottom: 1.48rem;
		}
		.desc {
			font-family: PingFangSC-Regular;
			font-size: 1.13rem;
			color: var(--setting-text-color);
			letter-spacing: 0;
			font-weight: 400;
			.desc-title {
				margin-bottom: 0.5rem;
			}
		}
		.desc-content {
			font-family: PingFangSC-Regular;
			font-size: 1.13rem;
			color: var(--setting-text-color);
			letter-spacing: 0;
			font-weight: 400;
		}
		.action {
			margin-top: 1.4rem;
		}
		.action button {
			border-radius: 1.8rem;
			padding: 0.5rem 2.05rem 0.5rem 2.05rem;
			height: 3rem;
		}
		.action /deep/.ivu-btn-default span {
			font-family: PingFangSC-Semibold;
			font-size: 1.13rem;
			line-height: 2rem;
			color: #ffffff;
			letter-spacing: 0;
			// line-height: 32px;
			font-weight: 600;
		}
	}
}
</style>
